package day07;

import javax.swing.*;
import java.awt.*;

public class Demo03 {
    public static void main(String[] args) {
        JFrame f = new JFrame("下雪");
        f.setSize(1366,768);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setBackground(Color.BLACK);
        SnowPanel sp = new SnowPanel();
        f.add(sp);
        f.setVisible(true);
        sp.snowing();
    }
}
class SnowPanel extends JPanel {
    int[] x = new int[200];
    int[] y = new int[200];
    public SnowPanel(){
        for(int i=0;i<200;i++){
            x[i] = (int)(Math.random()*1366);
            y[i] = (int)(Math.random()*768);
        }
    }

    @Override
    public void paint(Graphics g) {
        setBackground(Color.BLUE);
        g.clearRect(0,0,1366,768);
        g.setColor(Color.BLACK);
        g.setFont(new Font("",Font.BOLD,30));
        for(int i=0;i<200;i++){
            g.drawString("*",x[i],y[i]);
        }
    }

    public void snowing(){
        while(true){
            //坐标移动
            for(int i=0;i<200;i++){
                y[i]+=3;
                if(y[i]>=750){
                    y[i] = 0;
                }
            }
            try {
                Thread.sleep(1000/24);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            repaint();
        }
    }

}